import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';

class MyCrossController extends CrossoverController {
  RxList<String> types = [''].obs;
  RxList<String> slopelist = [''].obs;
  RxInt typeIndex_high = 0.obs;
  RxInt slopeIndex_high = 0.obs;
  RxInt typeIndex_low = 0.obs;
  RxInt slopeIndex_low = 0.obs;
  @override
  void onInit() {
    types.value = CHDefaultConfig().passTypes.map(($0) => $0.name).toList();
    slopelist.value = CHDefaultConfig().passTypes[0].slopeList.map(($0) => '${$0}dB/oct').toList();
    super.onInit();
  }

  ///选择group
  void chooseGroup(int index) {
    globalController.chooseGroup(groupList, groupList[index], 'XO');
  }

  ///group选中状态时，选中单通道
  void chooseChInGroup(ChannelModel ch) {
    final group = groupList.firstWhereOrNull(($0) => $0.ch1!.name == ch.name || $0.ch2!.name == ch.name);
    if (group == null) return;
    globalController.chooseChInGroup(groupList, group, ch, 'XO');
  }

  ///下拉框形式，选择滤波器类型
  void chooseType(Passmodel pass, int index) {
    pass.ishigh ? typeIndex_high.value = index : typeIndex_low.value = index;
    pass.ishigh ? slopeIndex_high.value = 0 : slopeIndex_low.value = 0;
    globalController.chooseFilterType(pass, CHDefaultConfig().passTypes[index]);
  }

  ///下拉框形式，选择斜率slope
  void chooseSlope(Passmodel pass, int index) {
    pass.ishigh ? slopeIndex_high.value = index : slopeIndex_low.value = index;
    globalController.updateSlope(pass, pass.type!.slopeList[index]);
  }
}
